#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

int random(); // 返回生成的随机数
int judge();  // 判断答案是否正确

double result = 0; //设置全局变量

int main()
{
    int i;     //定义变量
    int num1, num2;
    int yesorno;
    int count,wrongs=0,score=0;
    srand(time(NULL)); // 初始化随机数种子
    for (i = 1; i <= 10; i++)
    {
        num1 = random(); // 获取第一个随机数
        num2 = random(); // 获取第二个随机数

        printf("Question: %d / %d\n", num1, num2);
        result = (double)num1 / num2;

        count=0;   /*每个等式重置count值，使每一个等式都有三次机会*/

        while (count < 3)
        {
            yesorno = judge();

            if (yesorno == 1)
            {
                printf("Right!\n");
                score++;
                break;
            }
            else
            {
                printf("Not correct!\n");
                count++;
            }
            if(count == 3)
            {
                wrongs++;   /*三次机会都错误则错误加一*/
            }
        }
    }
    printf("You Score is %d\nYou have %d wrongs\n",score*10,wrongs);
    return 0;    /*在十个等式之后统计分数和错误个数*/
}

int random()
{
    return rand() % 10 + 1; // 生成1到10之间的随机数
}

int judge()
{
    double answer;
    printf("Please input answer: ");
    scanf("%lf", &answer); 

    if (fabs(result - answer) < 0.1)   /*浮点数储存会失真*/

    {
        return 1;
    }
    else
    {
        return 0;
    }
}